package com.oracle.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.oracle.pojo.Clazz;
import com.oracle.service.IClazzService;
import com.oracle.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
@Api(tags = "班级信息控制器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {

    @Autowired
    private IClazzService clazzService;
    /**
     * 模糊查询带分页操作
     */
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzsByConditionForPage(
            @ApiParam("分页查询页码") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("分页查询页大小") @PathVariable("pageSize") Integer pageSize,
            @ApiParam("模糊查询条件所属年级名称") String gradeName,
            @ApiParam("模糊查询条件班级名称") String name
    ){
        Page<Clazz> clazzPage = new Page<>(pageNo,pageSize);
        IPage<Clazz> page = clazzService.getClazzsByConditionForPage(clazzPage,gradeName,name);
        return Result.ok(page);
    }

    /**
     * 添加班级或者修改班级信息操作
     */
    @ApiOperation("添加班级或者修改班级信息功能")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(
            @ApiParam("添加或修改的班级信息类对象") @RequestBody Clazz clazz
    ){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }


    /**
     * 删除单条班级信息或者批量删除班级信息操作
     */
    @ApiOperation("删除单条班级信息或者批量删除班级信息功能")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazzsByIds(
            @ApiParam("删除单个记录或者批量删除的id数组") @RequestBody List<Integer> ids){
        clazzService.removeByIds(ids);
        return Result.ok();
    }

    /**
     * 查询所有班级  getStudentByOpr
     */
    @GetMapping("/getClazzs")
    @ApiOperation("获取所有班级信息操作")
    public Result getClazzsByCondition(){
        List<Clazz> classList = clazzService.getClazzs();

        return Result.ok(classList);
    }

}
